import instance from './axios';

// IAM登录接口
export const iamLogin = (params: any) => {
  return instance({
    url: '/v3/auth/tokens',
    method: 'post',
    data: {
      auth: {
        identity: {
          methods: ['password'],
          password: {
            user: {
              domain: {
                name: params.domainId, //IAM用户所属账号名
              },
              name: params.username, //IAM用户名
              password: params.password, //IAM用户密码
            },
          },
        },
        scope: {
          project: {
            name: localStorage.getItem('region'), //IAM用户所属账号名
          },
        },
      },
    },
  });
};

export const queryPhoneList = (params: any) => {
  return instance({
    url: `/v1/${params.project_id}/cloud-phone/phones`,
    method: 'get',
    headers: { 'x-Auth-token': localStorage.getItem('token') },
    params: {
      offset: params.offset,
      limit: params.limit,
      type: params.type,
      server_id: params.server_id,
    },
  });
};

export const queryPhonesConnectInfo = (params: any) => {
  return instance({
    url: `/v1/${params.project_id}/cloud-phone/phones/batch-connection`,
    method: 'post',
    headers: { 'x-Auth-token': localStorage.getItem('token') },
    data: {
      ...params,
    },
  });
};
